package com.bootdo.api;

import com.bootdo.common.controller.BaseController;
import com.bootdo.common.domain.DictDO;
import com.bootdo.common.request.Result;
import com.bootdo.common.request.ResultCode;
import com.bootdo.common.service.DictService;
import com.bootdo.common.utils.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/dict")
public class DictApiController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private DictService dictService;


    @ResponseBody
    @GetMapping("/list/{type}")
    public Result listByType(@PathVariable("type") String type) {
        try{
            // 查询列表数据
            Map<String, Object> map = new HashMap<>(16);
            map.put("type", type);
            List<DictDO> dictList = dictService.list(map);
            return  Result.success(dictList);
        }catch (Exception e){
            logger.error("【获取字典失败】报错："+e.getMessage());
            return  Result.error(ResultCode.ERROR,"获取字典失败！");
        }

    }
}
